package com.cn.topAndFoot.controller;

import com.cn.common.pojo.CompanyModel;
import com.cn.common.pojo.ResultModel;
import com.cn.topAndFoot.service.CompanyService;

import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;


@Api(tags = "公司信息")
@RestController
@RequestMapping("company")

public class CompanyController {
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date= DATE_FORMAT.format(new Date());

    @Autowired
    CompanyService companyService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @ApiOperation("公司信息删除")
    @GetMapping ("delete")
    public ResultModel delete(int id){
        ResultModel delete = companyService.delete(id);
        rabbitTemplate.convertAndSend("userTopicExchange","leader.hello","{reporter:'大哥好',date:\'"+date+"\',content:'公司信息已删除'}");
        return delete;
    }
    @ApiOperation("公司信息修改")
    @PostMapping("update")
    public ResultModel update(CompanyModel companyModel){
        ResultModel update = companyService.update(companyModel);
        rabbitTemplate.convertAndSend("userTopicExchange","leader.hello","{reporter:'大哥好',date:\'"+date+"\',content:'公司信息已修改'}");
        return update;
    }
    @ApiOperation("公司信息增加")
    @PostMapping(value = "insert")
    public ResultModel insert(CompanyModel companyModel){
        ResultModel insert = companyService.insert(companyModel);
        rabbitTemplate.convertAndSend("userTopicExchange","leader.hello","{reporter:'大哥好',date:\'"+date+"\',content:'新增了一条公司信息'}");
        return insert;
    }
    @ApiOperation("公司信息状态控制")
    @PostMapping(value = "enable")
    public ResultModel enable(int id){
        ResultModel enable = companyService.enable(id);
        return enable;
    }
    @ApiOperation("公司信息id查找")
    @GetMapping("findById")
    public ResultModel findById(int id){
        ResultModel findById = companyService.findById(id);
        return findById;
    }
    @ApiOperation("公司信息分页很全部信息")
    @GetMapping("limit")
    public ResultModel limit(int limit, int page){
        ResultModel all = companyService.findAll(limit,page);
        return all;
    }
}
